﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class SettingView : IUIView
{
    int index=0,oldIndex=0;
    public Button  game_btn,audio_btn,keyboard_btn,back_btn;
    public override void Initinalize()
    {
        game_btn.onClick.AddListener(SetGameModel);
        audio_btn.onClick.AddListener(SetAudio);
        keyboard_btn.onClick.AddListener(SetKeyBoard);
        back_btn.onClick.AddListener(Return);
        InitPointer();

    }
    public override void Hide()
    {
        base.Hide();

    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            if (index == 3) return;
            oldIndex = index;
            index++;
            index = Mathf.Clamp(index, 0, 3);
            OnPointerChange(oldIndex, index);
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            if (index == 0) return;
            oldIndex = index;
            index--;
            index = Mathf.Clamp(index, 0, 3);
            OnPointerChange(oldIndex, index);
        }
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            switch (index)
            {
                case 0:
                    SetGameModel();
                    break;
                case 1:
                    SetAudio();
                    break;
                case 2:
                    SetKeyBoard();
                    break;
                case 3:
                    Return();
                    break;
            }
        }
    }

    public void SetGameModel()
    {
        Hide();
        UIManager.Instance.modelSelectPanel.Show();
    }
    public void SetAudio()
    {
        Hide();
        UIManager.Instance.audioSettingPanel.Show();
    }
    public void SetKeyBoard()
    {
        Hide();
        UIManager.Instance.keySettiingPanel.Show();
    }
    public void Return()
    {
        Hide();
        UIManager.Instance.mainPanel.Show();
    }
    public override void Show()
    {

        InitPointer();
        base.Show();
    }
    void InitPointer()
    {
        oldIndex = index = 0;
        game_btn.transform.GetChild(0).gameObject.SetActive(true);
        audio_btn.transform.GetChild(0).gameObject.SetActive(false);
        keyboard_btn.transform.GetChild(0).gameObject.SetActive(false);
        back_btn.transform.GetChild(0).gameObject.SetActive(false);
    }
    void OnPointerChange(int oldIndex, int Index)
    {
        switch (oldIndex)
        {
            case 0:
                game_btn.transform.GetChild(0).gameObject.SetActive(false);
                break;
            case 1:
                audio_btn.transform.GetChild(0).gameObject.SetActive(false);
                break;
            case 2:
                keyboard_btn.transform.GetChild(0).gameObject.SetActive(false);
                break;
            case 3:
                back_btn.transform.GetChild(0).gameObject.SetActive(false);
                break;
        }
        switch (Index)
        {
            case 0:
                game_btn.transform.GetChild(0).gameObject.SetActive(true);
                break;
            case 1:
                audio_btn.transform.GetChild(0).gameObject.SetActive(true);
                break;
            case 2:
                keyboard_btn.transform.GetChild(0).gameObject.SetActive(true);
                break;
            case 3:
                back_btn.transform.GetChild(0).gameObject.SetActive(true);
                break;
        }


    }
}
